home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 109
/
Vol 109.iso
/
games
/
bubble_t.swf
/
scripts
/
frame_1
/
DoAction_3.as
< prev
next >
Wrap
Text File
|
2008-11-12
|
3KB
|
145 lines
function checkMatch(vBubble)
{
gGroup = [vBubble];
gStranded = new Array();
vBubble.pGroupIndex = 0;
searchMatch(vBubble,gGroup,vBubble.bubble._currentFrame);
if(2 < gGroup.length)
{
gStranded = getStranded();
gMode = cREMOVE;
gUnitScore = 2;
gMatchScore = 0;
gBonus = 1;
gTopLevel = 1000;
return true;
}
gMode = cNORMAL;
return false;
}
function searchMatch(vBubble, vGroup, vType)
{
var i = 0;
while(i < 6)
{
var lPos = getNeighborPos(vBubble,i);
var b = getBubbleAt(lPos.r,lPos.c);
if(b != 0 && b != -1)
{
if(vType)
{
if(!hasAt(vGroup,b,b.pGroupIndex))
{
if(b.bubble._currentFrame == vType)
{
vGroup.push(b);
b.pGroupIndex = vGroup.length - 1;
searchMatch(b,vGroup,vType);
}
}
}
else if(!hasAt(vGroup,b,b.pStrandedIndex))
{
if(!hasAt(gGroup,b,b.pGroupIndex))
{
vGroup.push(b);
b.pStrandedIndex = vGroup.length - 1;
searchMatch(b,vGroup,vType);
}
}
}
i++;
}
}
function getStranded()
{
gStranded = new Array();
var r0 = 0;
var c0 = -1;
var lDir = 5;
var lPoint = {r:r0,c:c0};
gEdgeGroup = new Array();
while(true)
{
while(true)
{
do
{
lDir = turnDir(lDir,1);
var lPos = dirToGrid(lDir);
var r = lPoint.r + lPos.dr;
var c = lPoint.c + lPos.dc;
}
while(r < 0);
var b = getBubbleAt(r,c);
var lStop = false;
if(b == 0 || b == -1)
{
lStop = true;
}
else if(hasAt(gGroup,b,b.pGroupIndex))
{
lStop = true;
}
if(lStop)
{
lPoint.r = r;
lPoint.c = c;
lDir = turnDir(lDir,-2);
break;
}
gEdgeGroup.push(b);
b.pEdgeGroupIndex = gEdgeGroup.length - 1;
}
if(Math.ceil(r / 2) + gRowLength - 1 < c)
{
break;
}
}
var i = 0;
while(i < gGroup.length)
{
var j = 0;
while(j < 6)
{
var lPos = getNeighborPos(gGroup[i],j);
var b = getBubbleAt(lPos.r,lPos.c);
if(b != 0 && b != -1)
{
if(!hasAt(gGroup,b,b.pGroupIndex))
{
if(!hasAt(gEdgeGroup,b,b.pEdgeGroupIndex))
{
if(!hasAt(gStranded,b,b.pStrandedIndex))
{
gStranded.push(b);
b.pStrandedIndex = gStranded.length - 1;
searchMatch(b,gStranded,0);
}
}
}
}
j++;
}
i++;
}
return gStranded;
}
function hasAt(vArray, vMember, vIndex)
{
if(vIndex == undefined)
{
return false;
}
if(vIndex >= vArray.length)
{
return false;
}
if(vMember == vArray[vIndex])
{
return true;
}
return false;
}